<#include "/common/freemarker/include_header.ftl">
<#--
加上后chrome显示不正常
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
-->
<#--
<html>
<head>
<meta   http-equiv="X-UA-Compatible"  content="IE=EmulateIE7" />  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<#macro context><#if request?exists>${request.getContextPath()}/<#else></#if></#macro>
<#assign ctx=request.getContextPath()>
<link rel='stylesheet' type='text/css' href='<@context/>/newface/commonTab/quickmenu_styles.css.ftl'/>
<script type='text/javascript' src='<@context/>/newface/commonTab/quickmenu.js.ftl'></script>
<link href="<@context/>/css/content.css" rel="stylesheet" type="text/css">
  <script src="<@context/>common/jquery-1.11.1/jquery.min.js"></script>
 --> 
<#--
<#include "/common/common.ftl">
<#include "/asframework/ftl/common-javascript-include-dialog.ftl" />
-->
<title>上传附件</title>
</head>

 

<div class="panel panel-default">
   <div clas="panel-body">
 
	<ul id="qm0" class="qmmc nav nav-tabs">
		<li class="active"><a class="qm-startopen qmparent" href="javascript:tabCtrl(1)">文件上传</a></li>
		<li><a class="qmparent" href="javascript:tabCtrl(0)">文件上传说明</a></li>
	</ul>
		
		    <div id="tab1" >
			 
			<span class="qmcbox" >
					<form name="frmUpload" id ="frmUpload"  Method="post" Enctype="multipart/form-data"  Action="<@context/>common/upload/saveFile.do" target="uploadFrame" onSubmit="return checkUpload()">
			<table border=0>
				<TR>
					<TD valign=top  width="50%">
					    <input class="btn btn-sm btn-default file" type="File" name="upload" id="AttachFileName" size="50" >
						<#-- <input type="file" class="file" name="upload" id="AttachFileName" >--> <#-- style="width:350px;height:30px; repeat-x bottom;color:#264c00;" background:url(${ctx}/images/bg_08.gif)-->
						<input type="hidden" name="FileName"><input type="hidden" name="index" value="-1">
						<div id="uploading" style="display:none"><font color=red>正在上传文件，请稍候 . . .</font></div>
					</TD>
					<TD valign=top width="49%">
						<input type="hidden" id="fildIds" name="fildIds">
						<input type="hidden" id="fildNames" name="fildNames">
						<input type="submit" class="btn btn-sm btn-primary" name="btnUpload" id="btnUpload" value="添 加"/>
                    	<input type="button" class="btn btn-sm btn-primary" value="确 定" onclick="javascript:btnOk()"/>
                    	<input type="button" class="btn btn-sm btn-default" value="取 消" onclick="javascript:closeAsDialog();"/>
                    	<#--	
						<@initBaseButton btType="submitBt" onclick="" alt="添 加" name="btnUpload" id="btnUpload" otherStr=""/>
						<@initBaseButton btType="commonBt" onclick="btnOk()" alt="确 定" name="btnOK" id="btnOK" otherStr=""/>
						<@initBaseButton btType="commonBt" onclick="closeAsDialog();" alt="取 消" name="btnOK" id="btnOK" otherStr=""/>
						-->
						<br>
					</TD>
				</TR>
			</table>
					</form>
			<br>
			<table id="uploadFileSel_Table" border="0" align="center" cellpadding="0" cellspacing="1" width="99%" class="content_tab_input">
				<tr class="content_tab_input">
					<td align="left" width="60%">
						<B>文件名</B>
					</td>
					<td width="20%" align="left">
						<B>操作</B>
					</td>
				</tr>
	        </table>
			</span>
			 
		 </div>
		
		
		    <div id="tab0" style="display:none">
			 
			<span class="qmcbox" >
			<table id="existsFileSel_Table" border="0" align="center" cellpadding="0" cellspacing="1" width="99%" class="content_tab_input">
				<tr>
					<td height="25" colspan=3 style="padding-left: 10px;">
						<font color="red">上传文件的过程分两个步骤，若要上传多个文件，请您根据需要重复下述操作。 </font>
					</td>
				</tr>
				<tr> 
					<td height="25" style="padding-left: 10px;">
						<font color="red" >
							&nbsp;&nbsp;&nbsp;&nbsp;1、单击“浏览”选择文件，或在下面的框中键入文件的路径。<BR>
							&nbsp;&nbsp;&nbsp;&nbsp;2、通过单击“添加”将文件上传到“附件”列表中。传输文件的时间可能需要5秒到10分钟。<BR>
							&nbsp;&nbsp;&nbsp;&nbsp;（注：文件请不要超过15M，否则会导致上传失败，不能正确响应。）<BR>
						</font>
					</td>
				</tr>
				<tr>
					<td height="25" colspan=3 style="padding-left: 10px;">
						 <font color="red" >当您完成后，请单击“确定”关闭窗口。</font></font>
					</td>
				</tr>				
	        </table>
			</span>
			 
	  	  </div>
	<iframe name="uploadFrame" width="0" height="0" frameborder="0"></iframe>
 </div>
</div> 
<script language="javascript">
	//qm_create(0,false,0,0,'all-always-open',false,false,true,false);//初始化视图
	
	var fname="${fname?if_exists}";
	var fnameList = fname.split(",");
	var parentWindow =art.dialog.data('parentWindow');
	var documentObj = parentWindow.document;<#--子窗口window.opener.document/iframe window.parent.document-->
    $(document).ready(function(){
    	var attachArr;
    	var attachIdArr;
    	var attachId = documentObj.getElementById(fnameList[0]).value;//as.dialog.getData("attachId");
    	var attachment = documentObj.getElementById(fnameList[1]).value;//as.dialog.getData("attachment");

    	if(!attachment || !attachId) {
    		return;
    	}
    	var attachArr = attachment.split(",");
    	var attachIdArr = attachId.split(",");
    	if(attachArr.length == attachIdArr.length) {
    		for(var i=0;i<attachArr.length;i++) {
    			attach(attachIdArr[i],attachArr[i]);
    		}
    	}
		
	});

	function checkUpload(){
		if(!$("#AttachFileName").val() || $("#AttachFileName").val()=="")
		{
			alert("请先找到您所要上传的附件文件！");
			$("#AttachFileName").focus();
			return false;
		}
		
		$("#uploading").show(1000);
		return true;
	}
	
	function attach(docId,filename) {
		$("#uploading").hide(3000);
		var html = jQuery("#uploadFileSel_Table").html() + "<TR id='file" + docId + "'><TD>" + filename + "</TD><TD><a href='<@context/>common/upload/deleteBatch.do?ExcelOut=" + docId + "' target='uploadFrame'>删 除</a></TD></TR>";
		jQuery("#uploadFileSel_Table").html(html);
		var fildIds 	= $("#fildIds").val();
		var fildNames	= $("#fildNames").val();
		if (fildIds==""){
			fildIds = docId;
		}else{
			fildIds = fildIds + "," + docId;
		}
		
		if (fildNames==""){
			fildNames = filename;
		}else{
			fildNames = fildNames + "," + filename;
		}
		
		$("#fildIds").val(fildIds);
		$("#fildNames").val(fildNames);
	}

	function btnOk(){
		var fvalue = "";
		var ftext = "";

		fvalue 	= $("#fildIds").val();
		ftext	= $("#fildNames").val();


		$(documentObj.getElementById(fnameList[0])).val(fvalue);
		$(documentObj.getElementById(fnameList[1])).val(ftext);
			
		parent.$(documentObj).find("#" + fnameList[0]).trigger("change");
		parent.$(documentObj).find("#" + fnameList[1]).trigger("change");
		
		//事实证明不能触发change事件,直接调用父窗口事件
		var onlyid =art.dialog.data('onlyid');
		if (onlyid!=null){
			//alert(onlyid);
			parentWindow.reloadImage(onlyid);
		}
		
		//documentObj.getElementById(fnameList[0]).value = fvalue;
	 	//documentObj.getElementById(fnameList[1]).value = ftext;	
	    //window.close();
	    //closewindow(1);
	    closeAsDialog();
	}

	function checkDelete() {
		if(!$("#ExcelOut").val() || $("#ExcelOut").val()==1){
			alert("请选择要删除 的文件");
			return false;
		}
		return true;
	}
	
	function removeDoc(strId) {
		var docId; 
		docId = strId.split(",");
		
		var fildIds 	= $("#fildIds").val();
		var fildNames	= $("#fildNames").val();
		
		fildIdList = fildIds.split(",");
		fildNameList = fildNames.split(",");
		for(var i=0;i<fildIdList.length;i++) {
			if (("," + strId + ",").indexOf("," + fildIdList[i] + ",") >-1){
				$("tr[id=file" + fildIdList[i] + "]").remove();
				fildIdList[i]=0;
				fildNameList[i]="";
			}
		}
		
		fildIds = "";
		fildNames = "";
		for(var i=0;i<fildNameList.length;i++) {
			if (fildNameList[i]!=""){
				if (fildIds==""){
					fildIds = "" + fildIdList[i];
					fildNames = "" + fildNameList[i];
				}else{
					fildIds = fildIds + "," + fildIdList[i];
					fildNames = fildNames + "," + fildNameList[i];
				}
			}
		}
		
		document.getElementById("fildIds").value = fildIds;
		document.getElementById("fildNames").value = fildNames;
	}
	function closeAsDialog()
	{
		art.dialog.close();			
	}
	function tabCtrl(index){
		$("#tab"+index).show();
		$("#tab"+(1-index)).hide();
		 
	}
</script>